package com.zn.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zn.mapper.UserRecordMapper;
import com.zn.pojo.UserRecord;
import com.zn.service.UserRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description
 * @Author zhaoning
 * @Date 2024/7/19
 */

@Service
public class UserRecordServiceImpl implements UserRecordService {

    @Resource
    private UserRecordMapper userRecordMapper;

    @Override
    public List<UserRecord> selectAllUserRecord() {
        QueryWrapper<UserRecord> queryWrapper = new QueryWrapper<>();

        return userRecordMapper.selectList(queryWrapper);
    }

    @Override
    public List<UserRecord> selectById(Integer id) {
        QueryWrapper<UserRecord> res = new QueryWrapper<>();
        res.eq("to_id", id);

        return userRecordMapper.selectList(res);
    }

    @Override
    public UserRecord save(UserRecord userRecord) {
        UserRecord newUserRecord;
        int isInsert = userRecordMapper.insert(userRecord);
        if (isInsert > 0) {
            newUserRecord = userRecord;
        } else {
            newUserRecord = null;
        }

        return newUserRecord;
    }
}
